package ace.module.oauth2.server.core.impl.authentication.ace;

import ace.module.oauth2.server.api.model.input.Oauth2AceAuthenticationInput;
import ace.module.oauth2.server.api.model.input.params.Oauth2AceAuthParamsMap;
import java.util.Map;
import java.util.Set;
import lombok.Getter;
import org.springframework.lang.Nullable;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationGrantAuthenticationToken;
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationToken;

/**
 * @author caspar
 * @date 2023/2/8 13:43
 */
public class Oauth2AceAuthenticationToken extends OAuth2AuthorizationGrantAuthenticationToken {

  @Getter
  private final Oauth2AceAuthenticationInput bodyModel;
  @Getter
  private final String bodyString;
  @Getter
  private final Set<String> requestedScopes;

  public Oauth2AceAuthenticationToken(
      AuthorizationGrantType authorizationGrantType,
      OAuth2ClientAuthenticationToken clientPrincipal,
      String bodyString,
      Oauth2AceAuthenticationInput bodyModel,
      Set<String> requestedScopes,
      @Nullable Map<String, Object> additionalParameters) {
    super(
        authorizationGrantType,
        clientPrincipal,
        additionalParameters
    );
    this.bodyModel = bodyModel;
    this.bodyString = bodyString;
    this.requestedScopes = requestedScopes;
  }

  public OAuth2ClientAuthenticationToken getOauth2ClientAuthenticationToken() {
    return (OAuth2ClientAuthenticationToken) this.getPrincipal();
  }
}
